<?php defined('IN_KG') or exit('Access Invalid!');?>
<link rel="stylesheet" type="text/css" href="<?php echo RESOURCE_SITE_URL;?>/js/jquery-ui/themes/ui-lightness/jquery.ui.css"  />
<script type="text/javascript" src="<?php echo RESOURCE_SITE_URL;?>/js/jquery.ajaxContent.pack.js"></script>
<script type="text/javascript" src="<?php echo RESOURCE_SITE_URL;?>/js/jquery-ui/jquery.ui.js"></script>
<style>
    .pic_list .small_pic ul li {
        height: 100px;
    }
    .ui-sortable-helper {
        border: dashed 1px #F93;
        box-shadow: 2px 2px 2px rgba(153,153,153, 0.25);
        filter: alpha(opacity=75);
        -moz-opacity: 0.75;
        opacity: .75;
        cursor: ns-resize;
    }
    .ui-sortable-helper td {
        background-color: #FFC !important;
    }
    .ajaxload {
        display: block;
        width: 16px;
        height: 16px;
        margin: 100px 300px;
    }
    #change_status{
        font-size: 12px;
        line-height: 30px;
        font-weight: bold;
        color: #FFF;
        background-color: #48CFAE;
        display: block;
        height: 30px;
        padding: 0 20px;
        border-radius: 3px;
        border: none 0;
        cursor: pointer;
    }
</style>
<pre hidden>
  <?php print_r($output['all_goods_list']); ?>
  <?php print_r($output['sortable']); ?>
</pre>
<input id="level2_flag" type="hidden" value="false" />
<input id="level3_flag" type="hidden" value="false" />
<div class="wrap">
    <div class="ncsc-form-default">
        <form id="add_form" method="post" action="index.php?control=store_promotion_xianshi&op=xianshi_save_list">
            <input type="hidden" id="on_status" name="on_status" value="0">
            <input type="hidden" name="xianshi_id" value="<?php echo $output['xianshi']['xianshi_id']?>">
            <dl>
               <dt></dt>
                <dd>
                    <tr>
                        <td class="w90 tr"><strong>活动名称：</strong></td>
                        <td class="w120 tl"><?php echo $output['xianshi']['xianshi_name']?></td>
                        <td class="w90 tr"><strong>开始时间：</strong></td>
                        <td class="w120 tl"><?php echo date('Y-m-d H:i:s',$output['xianshi']['start_time'])?></td>
                        <td class="w90 tr"><strong>结束时间：</strong></td>
                        <td class="w120 tl"><?php echo date('Y-m-d H:i:s',$output['xianshi']['end_time'])?></td>
                        <td class="w90 tr"><strong>购买下限：</strong></td>
                        <td class="w120 tl"><?php echo $output['xianshi']['lower_limit']?></td>
                        <td class="w90 tr"><strong>状态：</strong></td>
                        <td class="w120 tl">
                            <?php if ($output['xianshi']['state'] == 1){?>
                                正常
                            <?php }else{ ?>
                                取消
                            <?php } ?>
                        </td>
                    </tr>
                </dd>
            </dl>
            <dl>
                <dt></dt>
                <dd>
                    <p>
                        <input id="bundling_goods" type="hidden" value="" name="bundling_goods">
                        <span></span></p>
                    <table class="ncsc-default-table mb15">
                        <thead>
                        <tr>
                            <th class="w70">指定优惠</th>
                            <th class="tl" colspan="2">商品名称</th>
                            <th class="w90"><?php echo $lang['bundling_cost_price'];?></th>
                            <th class="w90">限时折扣价格</th>
                            <th class="w90"><?php echo $lang['nc_common_button_operate'];?></th>
                        </tr>
                        </thead>
                        <tbody nctype="bundling_data"  class="bd-line tip" title="<?php echo $lang['bundling_add_goods_explain'];?>">
                        <tr style="display:none;">
                            <td colspan="20" class="norecord"><div class="no-promotion"><i class="zh"></i><span>该限时折扣还未选择添加商品。</span></div></td>
                        </tr>
                        <?php if(!empty($output['b_goods_list'])){?>

                            <?php foreach($output['sortable'] as $k => $goods_common_id){?>
                                <?php $one = $output['all_goods_list'][$goods_common_id]; ?>
                                <tr id="bundling_tr_<?php echo $goods_common_id?>" class="off-shelf">
                                    <!-- <input type="hidden" value="<?php echo $val['bl_goods_id'];?>" name="goods[<?php echo $val['goods_id'];?>][bundling_goods_id]" /> -->
                                    <input type="hidden" value="<?php echo $goods_common_id;?>"  nctype="goods_id">
                                    <input type="hidden" value="<?php echo $goods_common_id;?>"  name="sort[]">
                                    <td class="w70">
                                        <input type="checkbox" name="goods[<?php echo $goods_common_id;?>][appoint]" value="1" <?php if ($one['goods_info']['bl_appoint'] == 1) {?>checked="checked"<?php }?>>
                                    </td>
                                    <td class="w50">
                                        <div class="shelf-state"><div class="pic-thumb"><img src="<?php echo cthumb($one['goods_info']['goods_image'], 60, $_SESSION['store_id']);?>">
                                            </div></div>
                                    </td>
                                    <td class="tl"><dl class="goods-name">
                                            <dt style="width: 360px;"><label style="display: block;" for="select_cb_<?php echo $goods_common_id; ?>"><?php echo $one['goods_info']['goods_name'];?></label><input type="checkbox" hidden checked="true" id="select_cb_<?php echo $goods_common_id; ?>" onchange="controlHide(this, <?php echo $goods_common_id; ?>)"></dt>
                                            <dd style="height: auto;width: 100%;" id="select_goods_<?php echo $goods_common_id; ?>">

                                                <?php foreach ($one['goods_list'] as $key => $goods) { ?>
                                                    <span><?php echo $goods['goods_name'] ?></span>
                                                    <p class="mb5"><span><?php echo "原价: $goods[goods_price] 现价: "; ?></span><input type="text" class="w50 text" value="<?php echo $goods['bl_goods_price'] ?>" data-price="<?php echo $goods['goods_price']; ?>" name="goods[<?php echo $goods_common_id ?>][<?php echo $goods['goods_id'] ?>]"  style="vertical-align: middle;"></p>
                                                <?php }?>

                                            </dd>
                                        </dl></td>
                                    <td class="goods-price w90" nctype="bundling_data_price"><?php echo ncPriceFormat($one['goods_info']['goods_price']);?></td>
                                    <td class="w90"><?php echo $val['goods_store_price'];?>
                                        <input nctype="price" type="hidden" value="<?php echo ncPriceFormat($one['goods_info']['goods_price']);?>"  class="text w70">
                                        <input type="text" value="" hdjtype="promotion_price" data-id="<?php echo $goods_common_id; ?>" data-price="<?php echo $one['goods_info']['goods_price'];?>" class="text w70" onkeydown="if(event.keyCode==13){return false;}">
                                    </td>
                                    <td class="nscs-table-handle w90"><span><a onclick="bundling_operate_delete($('#bundling_tr_<?php echo $goods_common_id?>'), <?php echo $goods_common_id?>)" href="JavaScript:void(0);" class="btn-bittersweet"><i class="icon-ban-circle"></i>
                  <p><?php echo $lang['bundling_goods_remove'];?></p>
                  </a></span></td>
                                </tr>
                            <?php }?>

                            <!-- <?php foreach($output['b_goods_list'] as $val){?>
              <?php if (isset($output['goods_list'][$val['goods_id']])) {?>
              <tr id="bundling_tr_<?php echo $val['goods_id']?>" class="off-shelf">
                <input type="hidden" value="<?php echo $val['bl_goods_id'];?>" name="goods[<?php echo $val['goods_id'];?>][bundling_goods_id]" />
                <input type="hidden" value="<?php echo $val['goods_id'];?>" name="goods[<?php echo $val['goods_id'];?>][gid]" nctype="goods_id">
                <td class="w70"><input type="checkbox" name="goods[<?php echo $val['goods_id'];?>][appoint]" value="1" <?php if ($val['bl_appoint'] == 1) {?>checked="checked"<?php }?>></td>
                <td class="w50"><div class="shelf-state"><div class="pic-thumb"><img src="<?php echo cthumb($output['goods_list'][$val['goods_id']]['goods_image'], 60, $_SESSION['store_id']);?>" ncname="<?php echo $output['goods_list'][$val['goods_id']]['goods_image'];?>" nctype="bundling_data_img">
                    </div></div>
                </td>
                <td class="tl"><dl class="goods-name">
                    <dt style="width: 300px;"><?php echo $output['goods_list'][$val['goods_id']]['goods_name'];?></dt>
                  </dl></td>
                <td class="goods-price w90" nctype="bundling_data_price"><?php echo ncPriceFormat($output['goods_list'][$val['goods_id']]['goods_price']);?></td>
                <td class="w90"><?php echo $val['goods_store_price'];?>
                  <input nctype="price" type="text" value="<?php echo ncPriceFormat($val['bl_goods_price']);?>" name="goods[<?php echo $val['goods_id'];?>][price]" class="text w70"></td>
                <td class="nscs-table-handle w90"><span><a onclick="bundling_operate_delete($('#bundling_tr_<?php echo $val['goods_id']?>'), <?php echo $val['goods_id']?>)" href="JavaScript:void(0);" class="btn-bittersweet"><i class="icon-ban-circle"></i>
                  <p><?php echo $lang['bundling_goods_remove'];?></p>
                  </a></span></td>
              </tr>
              <?php }?>
              <?php }?> -->
                        <?php }?>
                        </tbody>
                    </table>
                    <a id="bundling_add_goods" href="index.php?control=store_promotion_bundling&op=bundling_add_goods" class="ncbtn ncbtn-aqua">
                        添加商品
                    </a>
                    <div class="div-goods-select-box">
                        <div id="bundling_add_goods_ajaxContent"></div>
                        <a id="bundling_add_goods_delete" class="close" href="javascript:void(0);" style="display: none; right: -10px;">X</a></div>
                </dd>
            </dl>

            <div class="bottom">
                <label class="submit-border">
                    <!--<input id="submit_button" type="submit" value="<?php /*echo $lang['nc_submit'];*/?>"  class="submit">-->
                    <button type="submit"  id="change_status">提交</button>
                </label>
            </div>
        </form>
    </div>
</div>
<script src="<?php echo RESOURCE_SITE_URL;?>/js/common.js"></script>
<script src="<?php echo RESOURCE_SITE_URL;?>/js/jquery-ui/i18n/zh-CN.js"></script>
<script src="<?php echo SHOP_RESOURCE_SITE_URL;?>/js/store_bundling.js"></script>
<script src="<?php echo RESOURCE_SITE_URL;?>/js/jquery.poshytip.min.js"></script>
<script type="text/javascript">
    var DEFAULT_GOODS_IMAGE = '<?php echo defaultGoodsImage(60);?>';
    function controlHide(obj, id){
        var div = document.getElementById('select_goods_'+id);
        if (obj.checked) {
            div.style.display = 'block';
        }else{
            div.style.display = 'none';
        }
    }
    $(function(){
        jQuery.validator.addMethod('bundling_goods', function(value, element){
            return $('tbody[nctype="bundling_data"] > tr').length >2?true:false;
        });
        //Ajax提示
        $('.tip').poshytip({
            className: 'tip-yellowsimple',
            showTimeout: 1,
            alignTo: 'target',
            alignX: 'left',
            alignY: 'top',
            offsetX: 5,
            offsetY: -78,
            allowTipHover: false
        });
        $('.tip2').poshytip({
            className: 'tip-yellowsimple',
            showTimeout: 1,
            alignTo: 'target',
            alignX: 'right',
            alignY: 'center',
            offsetX: 5,
            offsetY: 0,
            allowTipHover: false
        });
        //页面输入内容验证
        $("#add_form").validate({
            errorPlacement: function (error, element) {
                var error_td = element.nextAll('span:first');
                error_td.append(error);
            },
            submitHandler: function (form) {
                ajaxpost('add_form', '', '', 'onerror')
            },
            rules: {
//                bundling_name: {
//                    required: true
//                },
//                bundling_goods: {
//                    bundling_goods: true
//                },
                discount_price: {
                    required: true,
                    number: true
                }
            },
            messages: {
//                bundling_name: {
//                    required: '<i class="icon-exclamation-sign"></i><?php //echo $lang['bundling_add_name_error'];?>//'
//                },
//                bundling_goods: {
//                    bundling_goods: '<i class="icon-exclamation-sign"></i><?php //echo $lang['bundling_add_goods_error'];?>//'
//                },
                discount_price: {
                    required: '<i class="icon-exclamation-sign"></i><?php echo $lang['bundling_add_price_error_null'];?>',
                    number: '<i class="icon-exclamation-sign"></i><?php echo $lang['bundling_add_price_error_not_num'];?>'
                }

            }
        });

        $('input[name="bundling_freight_choose"]').click(function(){
            if($(this).val() == '0'){
                $('#whops_buyer_box').show();
            }else{
                $('#whops_buyer_box').hide();
            }
        });

        check_bundling_data_length();
        <?php if(!empty($output['bundling_info'])){?>
        count_cost_price_sum(); // 计算商品原价
        count_price_sum();
        <?php }?>

        $('tbody[nctype="bundling_data"]').on('change', 'input[nctype="price"]', function(){
            count_price_sum();
        });


//        $('#change_status').onclick(function () {
//            $("#on_status").val(1);
//        })
    });


    /* 删除商品 */
    function bundling_operate_delete(o, id){
        o.remove();
        check_bundling_data_length();
        $('li[nctype="'+id+'"]').children(':last').html('<a href="JavaScript:void(0);" onclick="bundling_goods_add($(this))" class="ncbtn-mini ncbtn-mint"><i class="icon-plus"></i><?php echo $lang['bundling_goods_add_bundling'];?></a>');
        count_cost_price_sum();
    }

    function check_bundling_data_length(){
        if ($('tbody[nctype="bundling_data"] tr').length == 1) {
            $('tbody[nctype="bundling_data"]').children(':first').show();
        }
    }

//    document.getElementsById("btn_show_goods_select").onclick=function(){
//        $("#change_status").hide();
//    }

    /**/
    document.getElementById("bundling_add_goods_delete").onclick=function(){
        $("#on_status").val(1);
    }

</script>


<script>

</script>
